package com.bm.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.bm.entity.GcAl;

import com.bm.entity.Leave;
import com.bm.entity.News;
import com.bm.service.GcAlService;
import com.bm.service.LeaveService;
import com.bm.service.NewsService;
import com.bm.service.impl.GcAlServiceImpl;
import com.bm.service.impl.LeaveServiceImpl;
import com.bm.service.impl.NewsServiceImpl;
import com.bm.entity.PageBean;
import com.bm.entity.User;

/**
 * Servlet implementation class InsertServlet
 */
@WebServlet("/InsertServlet")
public class InsertServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public InsertServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		String num = request.getParameter("num");
		if(num.equals("2")) {
			request.getRequestDispatcher("insert.jsp").forward(request, response);
		}
		if(num.equals("3")) {
			request.setAttribute("url", "delet.jsp");
			request.getRequestDispatcher("delet.jsp").forward(request, response);
		}
		if(num.equals("4")) {
			request.setAttribute("url", "liuyan.jsp");
			LeaveService ls = new LeaveServiceImpl();
			List<Leave> leaveList = ls.qureyAllWord();
			request.setAttribute("leaveList", leaveList);
			request.getRequestDispatcher("liuyan.jsp").forward(request, response);
		}
		if(num.equals("7")) {
			GcAlService gs = new GcAlServiceImpl();
			int nums = Integer.parseInt(request.getParameter("nums"));
			PageBean<GcAl> gcList = new PageBean<GcAl>();
			gcList.setCount(nums);
			gcList = gs.pagesList(gcList);
			request.setAttribute("gcList",gcList);
			request.getRequestDispatcher("selectGc.jsp").forward(request, response);
			return;
		}
		if(num.equals("8")) {
			NewsService	ns = new NewsServiceImpl();
			int numss = Integer.parseInt(request.getParameter("numss"));
			PageBean<News> xwList = new PageBean<News>();
			xwList.setCount(numss);
			xwList = ns.pageList(xwList);
			request.setAttribute("xwList",xwList);
			request.getRequestDispatcher("selectXw.jsp").forward(request, response);
			return;
		}					
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
